<template>
  <div class="innerPage" v-if="page">
    <div class="inner-img">
      <div class="img-bg" v-if="VideoIndexOf(Contentlist.files ? Contentlist.files : Contentlist.cover)"
        :style="'background-image:url(' + Contentlist.cover + ') '">
        <!-- <div class="img-status">
          <img src="@/assets/image/status.png" alt="">
        </div> -->
      </div>
      <div class="videoContainer" v-else>
        <!-- <div class="img-status">
          <img src="@/assets/image/status.png" alt="">
        </div> -->
        <vdeo :collection='Contentlist.files' class="video" />

      </div>
    </div>
    <div class="bottom-bg"></div>
    <van-row justify="center">
      <van-col span="24" class="inner-title">
        <h1>{{ Contentlist.name }}</h1>

      </van-col>
      <van-col>
        <p class="linercolor">{{ Contentlist.code }}</p>
      </van-col>
      <van-col span="24" class="inner-title">
        <div class="Limit-warp">
          <span>限量</span>
          <span>{{ Contentlist.totalNumber ? Contentlist.totalNumber : "0" }}份</span>
        </div>
        <div class="Limit-warp">
          <span>剩余</span>
          <span>{{ Contentlist.surplusNumber ? Contentlist.surplusNumber : "0" }}份</span>
        </div>
      </van-col>
    </van-row>

    <div class="collect-info">
      藏品信息
    </div>
    <van-row justify="end" class="colletion-authon">
      <van-col span="12">创作者</van-col>
      <van-col span="12" class="right"><span>{{ Contentlist.serviceProvider }}</span></van-col>
    </van-row>
    <van-row justify="end" class="colletion-authon">
      <van-col span="12">发行方</van-col>
      <van-col span="12" class="right"><span>{{ Contentlist.mechanism }}</span></van-col>
    </van-row>
    <van-row justify="end" class="colletion-authon">
      <van-col span="6">合约地址</van-col>
      <van-col span="18" class="right">
        <p>{{ Contentlist.assetId ? Contentlist.assetId : '未上链' }}</p>
        <img src="@/assets/image/icon/copids.png" alt="" @click="copy">
      </van-col>
    </van-row>
    <van-row justify="end" class="colletion-authon" v-if="Contentlist.appName">
      <van-col span="12">中签可购</van-col>
      <van-col span="12" class="right"><span>{{ Contentlist.appName }}</span></van-col>
    </van-row>
    <div class="collect-info">
      藏品详情
    </div>
    <div class="story" v-html="Contentlist.story"></div>
    <div class="collect-info">
      购买须知
    </div>
    <div class="story"> 数字藏品为虚拟商品，而非实物，仅限实名认证的中国大陆用户购买，数字藏品的版权由发行方或原创作者拥有，除另外取得版权拥有者书面同意外，
      用户不得将数字藏品用于任何商业用途。本商品一经售出，不支持退换。本商品源文件不支持本地下载，请勿对数字藏品进行炒作/场外交易/欺诈或以任何其他非法方式进行使用。</div>
    <van-row justify="space-between" class="footer">
      <van-col span="12">
        <span class="price">￥{{ Contentlist.amount }}</span>
      </van-col>
      <van-col span="12" class="right">
        <van-button type="primary" v-if="Contentlist.sellStatus == 0" @click="openPwd" class="buy">
          <span>立即购买</span>
          <span> 剩余{{ Contentlist.surplusNumber }}份</span>
        </van-button>
        <van-button type="primary" v-if="Contentlist.sellStatus == 2" class="seing buy">
          <span>即将开售</span>

        </van-button>
        <van-button type="primary" v-if="Contentlist.sellStatus == 1" class="sed">
          <span>已售磐</span>
          <span></span>

        </van-button>
      </van-col>
    </van-row>

  </div>

  <Pwdwarp ref="PwdShow" :paydata="paydata" @updata:load="onLoad" />
</template>
<script>
import { reactive, computed, onMounted, defineComponent, onBeforeMount, ref, watch } from 'vue'
import Clipboard from 'clipboard';
import useClipboard from 'vue-clipboard3'
import { useStore } from "vuex";
import { useRouter } from "vue-router"
import { VideoIndexOf } from "@/utils/phone";
import Pwdwarp from "@/components/pwd.vue";
import { collectionInfo, needSynthesisList, shopping, findByBlindBox, getCollectionInfotype } from "@/api/public";
import { Toast, ImagePreview } from "vant";
import vueVideo from "@/components/vueVideo.vue";
import vdeo from "@/components/video.vue";
export default {
  components: {
    Pwdwarp, vueVideo, vdeo
  },
  setup(props) {
    onMounted(async () => {
      onLoad()
      await store.dispatch('user/getUserAll')

    })
    const store = useStore();
    const router = useRouter()
    const page = ref(false)
    const paytype = ref(true)
    const { toClipboard } = useClipboard()
    const Contentlist = ref({})
    const Available = ref([])
    const user_info = computed(() => {
      return store.getters.user_info
    })

    const onLoad = async () => {
      Toast.loading({
        message: '数据加载中...',
        forbidClick: true,
      });
      const data = { purchaseId: router.currentRoute.value.query.id }

      const res = await collectionInfo(data)
      if (res.data.success) {
        page.value = true
        Toast.clear()
        Contentlist.value = res.data.data
        console.log(res.data.data)
        if (Contentlist.value.propType == 3) {
          const data = { blindBoxId: router.currentRoute.value.query.id }
          findByBlindBox(data).then(e => {
            Available.value = e.data.data

          })
        }
      }

    }
    const paydata = ref({
      id: router.currentRoute.value.query.id,
      type: "1"
    })
    const PwdShow = ref(null)
    const openPwd = async () => {

      if (!store.getters.user_info.realName) {
        router.push('/realName')
        return false
      }
      if (!store.getters.user_info.payPassword) {
        router.push('/editPwd')
        return false
      }
      PwdShow.value.pwdopen = true
    }
    const toastname = (item) => {
      Toast(item.name)
    }
    const copy = async () => {
      try {
        await toClipboard(Contentlist.value.assetId)
        Toast("复制成功")
      } catch (e) {
        console.error(e)
      }
    }

    return {
      Contentlist, Available, onLoad, copy, openPwd, PwdShow, paydata, user_info, toastname, page, VideoIndexOf, paytype
    }
  }
}
</script>
<style lang="less" scoped>
.linercolor {
  font-size: 36px;
  width: fit-content;
  margin: 0px auto 20px;
  display: block;
}

.videoContainer {
  overflow: hidden;
  border-radius: 40px 40px 0px 0px;
  border: 1px solid #ffffff;

  .fullscreenVideo {
    width: 100%;
    //  width: 648px;
    height: 648px;
  }

  .img-status {
    position: absolute;
    right: 60px;
    top: 20px;

    img {
      width: 120px;
    }
  }
}

.videoContainers {
  position: relative;

  .img-status {
    position: absolute;
    right: 0px;

    img {
      width: 200px;
    }
  }

  .video {
    // width: 648px;
    // height: 648px;
    overflow: hidden;
    margin-top: 10px;

    .video {
      width: 100%;
      height: 348px;
    }
  }

  overflow: hidden;
  border-radius: 40px 40px 0px 0px;

  .fullscreenVideo {
    overflow: hidden;
    width: 100%;

    // height: 180px;
    source {
      width: 100%;
      border-radius: 40px 40px 0px 0px;
    }
  }
}

.innerPage {
  padding-bottom: 148px;

  .inner-img {
    overflow: hidden;
    width: 648px;
    height: 648px;
    background: linear-gradient(0deg, #161718, #4b4c4d);
    border: 2px solid #ffffff;
    border-radius: 80px;
    margin: 80px auto 20px;

    .img-bg {
      width: 100%;
      height: 100%;
      background-size: cover;
      // margin: 100px auto;
      position: relative;

      .img-status {
        position: absolute;
        right: 0px;

        img {
          width: 200px;
        }
      }
    }
  }

  .bottom-bg {
    background: url('../../../assets/image/bottom.png');
    width: 660px;
    height: 220px;
    background-size: cover;
    margin: 0px auto;
  }

  .inner-title {
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;

    h1 {
      font-size: 46px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      color: #f8f8f8;
      line-height: 103px;
      margin: 0px;
    }
  }

  .Limit-warp {
    margin-right: 20px;

    span {
      font-size: 26px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      line-height: 48px;
    }

    span:nth-child(1) {
      color: #444442;
      font-size: 26px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      background: #f3e3bb;
      border-radius: 4px 0px 0px 4px;
      padding: 3px 12px;
    }

    span:nth-child(2) {
      padding: 3px 12px;
      background: #444442;
      border-radius: 4px;
      font-size: 26px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      color: #f3e3bb;
      line-height: 48px;
    }
  }

  .colletion-authon {
    padding: 0px 18px;
    font-size: 34px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #ffffff;
    line-height: 140px;
    margin: 30px 20px 0px;
    height: 140px;
    background: #282a2c;
    border: 1px solid #ffffff;
    border-bottom: 0px;
    box-shadow: 0px 2px 30px 0px rgba(0, 0, 0, 0.35);
    border-radius: 20px;

    .right {
      display: flex;
      align-items: center;
      justify-content: flex-end;
      text-align: right;

      p {
        width: 80%;
        overflow: hidden;
        text-overflow: ellipsis;
      }

      img {
        width: 40px;
        margin-left: 20px;
      }

      text-align: right;

      span {
        text-align: center;
        font-size: 30px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #fefefe;
        background: linear-gradient(-90deg, #37dc6d 0%, #34d1f9 100%);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
      }
    }
  }

  .collect-info {
    z-index: 1;
    margin-top: 50px;
    font-size: 36px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #f8f8f8;
    margin-left: 20px;
    padding-left: 40px;
    position: relative;
  }

  .collect-info::after {
    opacity: 0.8;
    z-index: -1;
    background-size: 100% 100%;
    width: 70px;
    height: 60px;
    top: -10px;
    left: 0;
    position: absolute;
    content: '';
    background-image: url('../../../assets/image/point.png');
  }

  .Available {
    background: #282a2c;
    border-radius: 20px;
    margin: 30px 20px;
    padding: 20px 10px;

    .between-warp {
      position: relative;
      overflow: hidden;

      img {
        width: 100%;
        height: 180px;
      }
    }

    .img-warp {
      margin-top: 10px;
      // padding: 30px 10px;
      overflow: hidden;
      background: linear-gradient(0deg, #161718, #4b4c4d);
      border: 2px solid #ffffff;
      border-radius: 20px;
      background: linear-gradient(0deg, #161718, #4b4c4d);
      border: 2px solid #ffffff;
      border-radius: 20px;
    }
  }

  .story {
    background: #282a2c;
    border: 1px solid #ffffff;
    box-shadow: 0px 2px 16px 0px rgba(0, 0, 0, 0.35);
    border-radius: 20px;
    margin: 30px 30px;
    padding: 60px 30px;
    font-size: 28px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #ffffff;
    line-height: 48px;

    /deep/ img {
      width: 100%;
    }
  }

  .footer {
    width: 750px;
    padding: 30px 0px;
    background: #282a2c;
    position: fixed;
    bottom: 0px;
    z-index: 999;
    display: flex;
    align-items: center;

    .price {
      font-size: 46px;
      font-family: Source Han Sans CN;
      font-weight: bold;
      color: #f8f8f8;
      margin-left: 50px;
    }

    .right {
      padding-right: 20px;
      text-align: right;
      display: flex;
      justify-content: flex-end;
      // &:deep(.van-button) {

      // }
      .sed {
        border: none;
        border-radius: 62px;
        width: 256px;
        height: 74px;
        background: #7d8184 !important;
        border-radius: 32px;

        span {
          display: block;
          font-size: 28px;
          font-family: Source Han Sans CN;
          font-weight: 400;
          color: #ffffff;
          line-height: 26px;
        }
      }

      .buy {
        border: none;
        background: linear-gradient(-90deg, #37dc6d, #34d1f9);
        border-radius: 62px;
        width: 256px;
        height: 74px;

        span {
          display: block;
          color: #f8f8f8;
        }
      }
    }
  }
}

&:deep(.van-popup) {
  background: #000 !important;
}

.gift-warp {
  padding-top: 50px;

  i {
    top: 20px;
    right: 20px;
    position: absolute;
    color: #fefefe;
    font-size: 60px;
  }

  img {
    display: block;
    width: 625px;
    height: 415px;
    margin: 50px auto 0px;
  }

  .box-btn {
    font-size: 32px;
    display: block;
    border: none;
    width: 448px;
    height: 80px;
    background: linear-gradient(-90deg, #37dc6d, #34d1f9);
    margin: 20px auto;
  }

  h1 {
    text-align: center;
    font-size: 48px;
    font-family: Source Han Sans CN;
    font-weight: bold;
    color: #f3e3bb;
    line-height: 42px;
    margin: 40px 0px;
  }

  width: 688px;
  height: 777px;
  background-image: url('../../../assets/image/giftbg.png');
  background-size: 100% 100%;
}
</style>